-
Notifications
You must be signed in to change notification settings - Fork 510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: get start number from muxer and specify initial sequence number #879
Conversation
@sr1990 thanks for putting in PR. Initial testing looks good to me. I can try and run more variants if I get time.
|
@kqyang Do you think this PR can be merged? Our initial testing looks good. We are waiting on this patch do deliver dash manifest to ps4 devices. Thanks. |
@@ -17,3 +17,8 @@ MP4 output options | |||
template). | |||
|
|||
Default enabled. | |||
|
|||
--mp4_initial_sequence_number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this feature. Here is my high level feedback.
There are two concepts in this CL.
-
mp4_initial_sequence_number which specifies the initial sequence number in moof->mfhd.
-
the starting segment index.
They are different concepts. They may not have the same value as a segment can contain multiple fragments.
Can we have a separate flag for segment index, e.g. start_segment_number to match the startNumber
in DASH SegmentTemplate
?
I think we can remove the initial sequence number from this PR (or move it to a separate PR).
I also think that it can be a ChunkingParam as it is not restricted to mp4.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback.
They are different concepts. They may not have the same value as a segment can contain multiple fragments.
You are right. My mistake. What is the use-case for specifying moof->mfhd sequence number?
I do not see exoplayer's FragmentedMp4Extractor.java parsing it
https://github.com/google/ExoPlayer/blob/03263db378392385e290c40505d80e990c85a5cb/library/extractor/src/main/java/com/google/android/exoplayer2/extractor/mp4/FragmentedMp4Extractor.java#L708
Can we have a separate flag for segment index, e.g. start_segment_number
to match the startNumber in DASH SegmentTemplate?
I also think that it can be a ChunkingParam as it is not restricted to mp4.
Yes that makes sense. Will look into it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the use-case for specifying moof->mfhd sequence number?
I don't really know. None of the players and devices I know care about the sequence number in mfhd. That is actually the question I have in the original PR (#270) too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that makes sense.. we can keep it out. I don't know of use-cases either where it would be needed to change the initial sequence number of moof -> mfhd.
From what I understand was that segment index start should be enough to fix console platform issues and align us with the DASH spec, that should be the only validation happening player side. Beyond that it just uses either index ranges or the indexed fragmented files from origin for delivery.
89983c1
to
b31c7cd
Compare
@vish91, @kqyang, I have added a start_segment_number flag to indicate startNumber in SegmentTemplate.
Please review and let me know. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating the code. It looks mostly good.
I left a number of comments, with most of them as formatting issues.
As I have suggested in your earlier PRs, you can use clang-format
to format the code properly:
$ git clang-format
If HEAD^
is the original commit:
$ git clang-format HEAD^
|
||
--start_segment_number | ||
|
||
Indicates the startNumber in DASH SegmentTemplate. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically it applies to HLS as well. Can we rephrase it to something like:
Indicates the startNumber in DASH SegmentTemplate and HLS segment name.
Same elsewhere.
packager/app/packager_main.cc
Outdated
if (chunking_params.start_segment_number < 0) { | ||
LOG(ERROR) << "Negative --start_segment_number not allowed."; | ||
return base::nullopt; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check should be moved to packager.cc, e.g. in ValidateParams
packager/app/test/packager_test.py
Outdated
@@ -478,7 +478,8 @@ def _GetFlags(self, | |||
default_language=None, | |||
segment_duration=1.0, | |||
use_fake_clock=True, | |||
allow_codec_switching=False): | |||
allow_codec_switching=False, | |||
start_segment_number=-1): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use None to indicate that it is not set:
start_segment_number=None
packager/app/test/packager_test.py
Outdated
self.assertPackageSuccess(streams, self._GetFlags(output_dash=True, | ||
start_segment_number=0)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you align it properly?
packager/media/base/text_muxer.cc
Outdated
@@ -49,7 +49,7 @@ Status TextMuxer::Finalize() { | |||
|
|||
muxer_listener()->OnNewSegment( | |||
options().output_file_name, 0, | |||
duration_seconds * streams()[0]->time_scale(), size); | |||
duration_seconds * streams()[0]->time_scale(), size, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you define a named constant or add a comment here for better readability?
e.g.
// The segment index does not matter for single segment output.
const uint32_t kArbitrarySegmentIndex = 0;
OnNewSegment(....,, kArbitrarySegmentIndex);
packager/mpd/base/representation.h
Outdated
// startNumber attribute for SegmentTemplate. | ||
// Starts from 1. | ||
uint32_t start_number_ = 1; | ||
bool stream_just_started_ = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it part of this this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed it.
if (start_segment_index_ == -1) | ||
start_segment_index_ = start_time / duration; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. Removed it.
segment_info->segment_index = current_segment_index_ + | ||
num_segments_before_last_cue_ + | ||
chunking_params_.start_segment_number - 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a potential behavior change.
- In the original code, the segment_index starts with 0 and is always monotonically increasing.
- In the new code, the segment_index is related to the segment timestamp.
Can we move the behavior change to a separate PR and focus this PR on start segment number?
So in this PR, we can just set the initial segment_index to chunking_params_.start_segment_number - 1 and increases by 1 for every new segment.
The comment applies to text_chunker below too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Let's do that.
TextChunker::TextChunker(double segment_duration_in_seconds, | ||
int64_t start_segment_number) | ||
: segment_duration_in_seconds_(segment_duration_in_seconds), | ||
start_segment_number_(start_segment_number){}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs to be reformatted
@@ -42,7 +42,8 @@ class CombinedMuxerListener : public MuxerListener { | |||
void OnNewSegment(const std::string& file_name, | |||
int64_t start_time, | |||
int64_t duration, | |||
uint64_t segment_file_size) override; | |||
uint64_t segment_file_size, | |||
int64_t segment_index) override; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer segment_number
so it matches with the file_name. What do you think? A number of files will need to be updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kqyang Do you prefer changing segment_index in struct SegmentInfo, SegmentEventInfo, and kSegmentIndex in unit tests to kSegmentNumberl? Or just the methods with file_name parameter in it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should. There should be as few unnecessary "+1" or "-1" as possible. (If I have overlooked anything, let me know)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
const char kSegment2Name[] = "memory://test_2.aac"; | ||
const char kSegment124Name[] = "memory://test_124.aac"; | ||
const char kSegment125Name[] = "memory://test_125.aac"; | ||
const int64_t kSegmentIndex123 = 123; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, didn't notice that. It is fine to keep it as is then.
@@ -271,8 +268,11 @@ base::Optional<xml::XmlNode> Representation::GetXml() { | |||
} | |||
|
|||
if (HasLiveOnlyFields(media_info_) && | |||
!representation.AddLiveOnlyInfo(media_info_, segment_infos_, | |||
start_number_)) { | |||
!representation.AddLiveOnlyInfo( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or perhaps adding start_number only if segment_infos is not empty, e.g.
if (media_info.has_segment_template_url() && !segment_infos.empty()) {
@@ -42,7 +42,8 @@ class CombinedMuxerListener : public MuxerListener { | |||
void OnNewSegment(const std::string& file_name, | |||
int64_t start_time, | |||
int64_t duration, | |||
uint64_t segment_file_size) override; | |||
uint64_t segment_file_size, | |||
int64_t segment_index) override; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should. There should be as few unnecessary "+1" or "-1" as possible. (If I have overlooked anything, let me know)
b31c7cd
to
c496378
Compare
Hey @sr1990 or @kqyang just noticed that we are also implementing HLS for this flag. |
@vish91 Looks like there is already a flag to specify EXT-X-MEDIA-SEQUENCE explicitly. |
@vish91 Can you clarify what you mean? The current change does not affect the media sequence number.
Yes, there are overlaps. We could set the media sequence number to start_segment_number; we could also just keep them separate. I prefer having them separate for now to avoid affecting the current behavior. |
Yes agree. I prefer it separate as well.
I meant to ask do we even need a feature like this for HLS in first place ? since HLS uses the Media Sequence tag which already starts from 0 and isn't really affected by sequence ID on the segment name. |
@kqyang I have updated the PR to change segment number as 1 based. Please review and let me know. |
Looks good to me. And it would be useful when the packager restarts for any reason to "continue" from where it left off. |
When can we expect to be merged. |
This can't be merged as-is. There are many merge conflicts, and that doesn't even account for the changes coming from the Please be patient with us as we clean up and modernize the code, its dependencies, and its build system. Then we can work with PR authors to fix/reimplement their changes and merge them. |
I rebased this and made a few updates and all tests seem to pass locally. |
packager/app/test/packager_test.py
Outdated
@@ -575,6 +575,9 @@ def _GetFlags(self, | |||
elif force_cl_index is False: | |||
flags += ['--noforce_cl_index'] | |||
|
|||
if start_segment_number: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe if start_segment_number is not None:
so that a start number of 0 is permitted.
🤖 I have created a release *beep* *boop* --- ## [3.1.0](v3.0.4...v3.1.0) (2024-05-03) ### Features * add missing DASH roles from ISO/IEC 23009-1 section 5.8.5.5 ([#1390](#1390)) ([fe885b3](fe885b3)) * get start number from muxer and specify initial sequence number ([#879](#879)) ([bb104fe](bb104fe)) * teletext formatting ([#1384](#1384)) ([4b5e80d](4b5e80d)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
@kqyang Have merged #818 and #519 by @sammirata along with the changes mentioned in #519.
Example:
../packager 'in=Sintel-1280x720.mp4,stream=video,init_segment=h264_1280p/init.mp4,segment_templa te=h264_1280p/$Number$.m4s' --mpd_output h264.mpd --mp4_initial_sequence_number 0
Please review and let me know.
Thanks.